/* Copyright 2009 Sony Mathew, Minneapolis MN. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at  http://www.apache.org/licenses/LICENSE-2.0  Unless required by applicable law or agreed to in writing, software  distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */
package com.xsm.gwt.widgets.client;

import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.SimplePanel;
import com.google.gwt.user.client.ui.Widget;

/**
 * @author Sony Mathew
 */
public class AxisTableDemoPanel extends SimplePanel {
    
    /**
     * Building row by row without indexing into cells directly.
     * Places widgets directly in the cells.
     * 
     * author Sony Mathew
     */
    public AxisTableDemoPanel buildRowByRowPlaceDirectDemo() {
        AxisTable table = new AxisTable().border(2)
        
        //demo header
        .nextRow()
            .put("AxisTable Demo: buildRowByRowPlaceDirectDemo")
        
        //drug & costs header
        .nextRow()
            .put("Drug Name").align(1,0)            
            .put("--").align(0,0)
            .put("Specialty").align(1,0)
            .put("90 Day Mail").align(1,0)
            .put("90 Day Retail").align(1,0)
            .put("30 Day Retail").align(1,0)
            
        //drug info & total costs              
        .nextRow() 
            .put(new AxisPanel()
                    .x("PAXIL").q()
                    .x("The Wonder Drug").q()
                    .x("The Calming Drug").q()                
                  )
            .put("Total Costs")
            .put("100.00")
            .put("101.01")
            .put("102.02")
            .put("103.03")
            
        //your costs
        .nextRow()
            .put("Your Costs")
            .put("200.00")
            .put("202.02")
            .put("203.03")
            .put("204.04")
            
        //my costs
        .nextRow()
            .put("My Costs")
            .put("300.00")
            .put("302.02")
            .put("303.03")
            .put("304.04")
            
        //demo header //span across all columns            
        .cell(0,0).span(1,7)

        //drug header //span 2 columns           
        .cell(1,0).span(1,2)
        
        //drug info //span 3 rows and 2 columns.               
        .cell(2,0).span(3,2) 
        
        ;//end
        
        setWidget(table);
        return this;
    }
    
    /**
     * Building by indexing into cells directly and also uses rowspan/colspan.
     * Places widgets directly in the cells.
     * 
     * author Sony Mathew
     */
    public AxisTableDemoPanel buildIndexCellPlaceDemo() {
        AxisTable table = new AxisTable().border(2)
        
        //demo header //span accross all columns
        .cell(0,0).span(1,7).put("AxisTable Demo: buildIndexCellPlaceDemo()")
        
        //drug header //span 2 columns
        .cell(1,0).span(1,2).put("Drug Name")            
        //costs header
        .cell(1,1).put("--")
        .cell(1,2).put("Specialty")
        .cell(1,3).put("90 Day Mail")
        .cell(1,4).put("90 Day Retail")
        .cell(1,5).put("30 Day Retail")
            
        //drug info //span 3 rows and 2 columns.               
        .cell(2,0).span(3,2)
            .put(new AxisPanel()
                    .x("PAXIL").q()
                    .x("The Wonder Drug").q()
                    .x("The Calming Drug").q()             
                  )
                  
        //total costs
        .cell(2,1).put("Total Cost")
        .cell(2,2).put("100.00")
        .cell(2,3).put("101.01")
        .cell(2,4).put("102.02")
        .cell(2,5).put("103.03")
            
        //your costs
        .cell(3,0).put("Your Cost")
        .cell(3,1).put("200.00")
        .cell(3,2).put("202.02")
        .cell(3,3).put("203.03")
        .cell(3,4).put("204.04")
            
        //my costs
        .cell(4,0).put("My Cost")
        .cell(4,1).put("300.00")
        .cell(4,2).put("302.02")
        .cell(4,3).put("303.03")
        .cell(4,4).put("304.04")
            
        ;//end
        
        setWidget(table);
        return this;
    }
    
    /**
     * Building row by row without indexing into cells directly.
     * Places widgets directly in the cells.
     * Overlay on certain row/cells by indexing into them.
     * 
     * author Sony Mathew
     */
    public AxisTableDemoPanel buildOverlayByIndexBoundsDemo() {
        AxisTable table = new AxisTable().border(2)
        
        //demo header
        .nextRow().css("demoHeaderRow")
            .put("AxisTable Demo: buildOverlayByIndexBoundsDemo").span(1,7)
        
        //drug header row
        .nextRow().css("drugHeaderRow")
            .put("Drug Name").span(1,2)            
            .put("--")
            .put("Specialty")
            .put("90 Day Mail")
            .put("90 Day Retail")
            .put("30 Day Retail")
            
        //drug info & total costs              
        .nextRow() 
            .put(new AxisPanel()
                    .x("PAXIL").q()
                    .x("The Wonder Drug").q()
                    .x("The Calming Drug").q()                
                  ).span(4,2)
            .put("Total Costs")
            .put("100.00")
            .put("101.01")
            .put("102.02")
            .put("103.03")
            
        //your costs
        .nextRow()
            .put("Your Costs")
            .put("200.00")
            .put("202.02")
            .put("203.03")
            .put("204.04")
            
        //my costs
        .nextRow()
            .put("My Costs")
            .put("300.00")
            .put("302.02")
            .put("303.03")
            .put("304.04")
            
        ;//end
        
        Button ob;
        
        ob = new Button("Overlayed 100.00 - 103.03");
        AxisTable.Overlay o1 = table.createOverlay(2, 2, 2, 5)
            .put(decor(ob));
        o1.overlay();

        ob = new Button("Overlayed Paxil info");
        AxisTable.Overlay o2 = table.createOverlay(2, 0, 2, 0)
            .span(3,2).put(decor(ob));
        o2.overlay();

        ob = new Button("Overlayed 302.02 - 304.04");
        AxisTable.Overlay o3 = table.createOverlay(4, 2, 4, 4)
            .put(decor(ob));
        o3.overlay();
        
        setWidget(table);
        return this;
    }
    
    /**
     * Building row by row without indexing into cells directly.
     * Places widgets directly in the cells.
     * Overlay on certain row/cells by identifying widgets to coverup.
     * 
     * author Sony Mathew
     */
    public AxisTableDemoPanel buildOverlayByWidgetBoundsDemo() {
        Widget paxilInfo, totalCosts, yourCosts, myCosts, cost100, cost103, cost202, cost203, cost302, cost304 = null; 

        AxisTable table = new AxisTable().border(1).space(0).pad(1)
                    
        //demo header
        .nextRow().css("demoHeaderRow")
            .put("AxisTable Demo: buildOverlayByWidgetBoundsDemo").span(1,7)
        
        //drug & costs header
        .nextRow().css("drugHeaderRow")
            .put("Drug Name").span(1,2)            
            .put("--")
            .put("Specialty")
            .put("90 Day Mail")
            .put("90 Day Retail")
            .put("30 Day Retail")

        .nextRow() 
            .put(paxilInfo = new AxisPanel()
                    .x("PAXIL").q()
                    .x("The Wonder Drug").q()
                    .x("The Calming Drug").q()                
                 ).span(4,2)
            
        //total costs              
        .nextRow() 
            .put(totalCosts = new Label("Total Costs"))
            .put(cost100 = new Label("100.00"))
            .put("101.01")
            .put("102.02")
            .put(cost103 = new Label("103.03"))
            
        //your costs
        .nextRow()
            .put(yourCosts = new Label("Your Costs"))
            .put("200.00")
            .put(cost202 = new Label("202.02"))
            .put(cost203 = new Label("203.03"))
            .put("204.04")
            
        //my costs
        .nextRow()
            .put(myCosts = new Label("My Costs"))
            .put("300.00")
            .put(cost302 = new Label("302.02"))
            .put("303.03")
            .put(cost304 = new Label("304.04"))            
        ;//end
        
        Button ob;
        
        ob = new Button("Overlayed Paxil info");
        AxisTable.Overlay oi = table.createOverlay(paxilInfo)
            .span(4,2).put(decor(ob));
        oi.overlay();
        
        ob = new Button("Overlayed 100.00 - 103.03");
        AxisTable.Overlay o1 = table.createOverlay(cost100, cost103)
            .put(decor(ob));
        o1.overlay();

        ob = new Button("Overlayed 202.00 - 203.04");
        AxisTable.Overlay o2 = table.createOverlay(cost202, cost203)
            .put(decor(ob));
        o2.overlay();
        
        ob = new Button("Overlayed 302.02 - 304.04");
        AxisTable.Overlay o3 = table.createOverlay(cost302, cost304)
            .put(decor(ob));
        o3.overlay();

        AxisPanel o4c = new AxisPanel().put("Overlayed").put("Costs").put("Labels");
        AxisTable.Overlay o4 = table.createOverlay(totalCosts, myCosts)
            .put(decor(o4c));
        o4.overlay();
        
        setWidget(table);
        return this;
    }
    
    /**
     * Build an axis table using a TH header.
     * 
     * author Sony Mathew
     */
    public AxisTableDemoPanel buildWithTHHeader() {
        Widget paxilInfo, totalCosts, yourCosts, myCosts, cost100, cost103, cost202, cost203, cost302, cost304 = null; 

        AxisTable table = new AxisTable().border(1).space(0).pad(1);
                    
        table.createHeaderRow();
        table.addHeaderHTML("<span style=\"font-size:3em\">Drug Name</span>");
        table.setHeaderText(1, "----");
        table.setHeaderText(2, "Specialty");
        table.addHeaderText("90 Day Mail");
        table.addHeaderText("90 Day Retail");
        table.addHeaderText("30 Day Retail");
        
        table        
        .nextRow() 
            .put(paxilInfo = new AxisPanel()
                    .x("PAXIL").q()
                    .x("The Wonder Drug").q()
                    .x("The Calming Drug").q()                
                 ).span(4,1)
            
        //total costs              
        .nextRow() 
            .put(totalCosts = new Label("Total Costs"))
            .put(cost100 = new Label("100.00"))
            .put("101.01")
            .put("102.02")
            .put(cost103 = new Label("103.03"))
            
        //your costs
        .nextRow()
            .put(yourCosts = new Label("Your Costs"))
            .put("200.00")
            .put(cost202 = new Label("202.02"))
            .put(cost203 = new Label("203.03"))
            .put("204.04")
            
        //my costs
        .nextRow()
            .put(myCosts = new Label("My Costs"))
            .put("300.00")
            .put(cost302 = new Label("302.02"))
            .put("303.03")
            .put(cost304 = new Label("304.04"))            
        ;//end
        
        setWidget(table);
        return this;
    }
    
    private Widget decor(Widget w) {
        return new AxisPanel().stretch().align(0,0).styleBorder(1, "blue").put(w);
    }
}
